home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
aminet
/
dev
/
lang
/
perl4_bin_035_v010.lzh
/
perl4.035
/
lib
/
getcwd.pl
< prev
next >
Wrap
Text File
|
1992-08-05
|
1KB
|
63 lines
# By Brandon S. Allbery
#
# Usage: $cwd = &getcwd;
sub getcwd
{
local($dotdots, $cwd, @pst, @cst, $dir, @tst);
unless (@cst = stat('.'))
{
warn "stat(.): $!";
return '';
}
$cwd = '';
do
{
$dotdots .= '/' if $dotdots;
$dotdots .= '..';
@pst = @cst;
unless (opendir(getcwd'PARENT, $dotdots)) #'))
{
warn "opendir($dotdots): $!";
return '';
}
unless (@cst = stat($dotdots))
{
warn "stat($dotdots): $!";
closedir(getcwd'PARENT); #');
return '';
}
if ($pst[$[] == $cst[$[] && $pst[$[ + 1] == $cst[$[ + 1])
{
$dir = '';
}
else
{
do
{
unless ($dir = readdir(getcwd'PARENT)) #'))
{
warn "readdir($dotdots): $!";
closedir(getcwd'PARENT); #');
return '';
}
unless (@tst = stat("$dotdots/$dir"))
{
warn "stat($dotdots/$dir): $!";
closedir(getcwd'PARENT); #');
return '';
}
}
while ($dir eq '.' || $dir eq '..' || $tst[$[] != $pst[$[] ||
$tst[$[ + 1] != $pst[$[ + 1]);
}
$cwd = "$dir/$cwd";
closedir(getcwd'PARENT); #');
} while ($dir);
chop($cwd);
$cwd;
}
1;